// templates/deliver/pages/abnormalOrderAll/abnormalOrderAll.js
import Toast from '@vant/weapp/toast/toast';
import Notify from '@vant/weapp/notify/notify';
import Dialog from '@vant/weapp/dialog/dialog';
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: 0, //司机id
        name: '', //司机姓名
        orderAll: [], //订单数据
        activeNames: ['1'],

        view_delivery_man_id: 0,
        view_driver_name: '',
        view_delivery_district_id: 0

    },
    /**
     * 打开折叠面板
     */
    onChange(event) {
        this.setData({
          activeNames: event.detail,
        });
      },
      /**
       * 解除异常
       */
      relieve(e){
        let that = this
        let id = e.currentTarget.dataset.id
        let name = e.currentTarget.dataset.name
        let url =  app.globalData.URL
        let mall_id  = app.globalData.mall_id
        Dialog.confirm({
            title: '解除异常',
            message: '确认是否'+ name +'订单已解除异常~~',
          })
            .then(() => {
              // on confirm
              wx.request({
                url: url + '/deliver.Order/relieveOrder',
                method: "GET",
                data:{
                    id,
                    mall_id
                },
                success(res){
                    if(res.data.code === 0){
                    Notify({ type: 'warning', message: '解除成功' });
                    that.abnormalOrderAll()
                    }else{
                        Notify({ type: 'warning', message: '解除失败' });
                    }
                }
              })
            })
            .catch(() => {
              // on cancel
              Notify({ type: 'warning', message: '取消解除' });
            });
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

        let view_delivery_man_id = wx.getStorageSync('view_delivery_man_id') || 0
        let view_driver_name = ''
        let view_delivery_district_id = 0
        if (view_delivery_man_id > 0) {
            view_driver_name = wx.getStorageSync('view_driver_name')
            view_delivery_district_id = wx.getStorageSync('view_delivery_district_id')
        }

        this.setData({
            id: options.city_id,
            name: options.city_name,
            view_delivery_man_id,
            view_driver_name,
            view_delivery_district_id
        })

        this.abnormalOrderAll()
    },
    /**
     * 根据司机信息查询异常订单， 待处理的
     */
    abnormalOrderAll(){
        let that = this 
        let url =  app.globalData.URL
        let mall_id  = app.globalData.mall_id
        let id  =  that.data.id
        let name =  that.data.name
        wx.request({
          url: url + '/deliver.Order/abnormalOrderAll',
          method: "POST",
          data:{
              mall_id,
              id,
              name
          },
          success: res=>{
              if(!res.data.data){
                Toast.fail('没数据~~');
                that.setData({
                    orderAll: []
                  })
              }
              that.setData({
                orderAll: res.data.data
              })
           
          }
        })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})